package calcs;

import gui.MyFrame;
import gui.data.D3.PointsIn3DOutputGui;
import static util.Util.*;

public class XYZDistanceCalculator extends Thread{
	double x1, x2, y1, y2, z1, z2, distance, dx, dy, dz;
	String vector = "";
	MyFrame myFrame;

	public XYZDistanceCalculator(double x1, double y1, double z1, double x2, double y2, double z2, MyFrame myFrame) {
		this.x1 = x1;
		this.x2 = x2;
		this.y1 = y1;
		this.y2 = y2;
		this.z1 = z1;
		this.z2 = z2;
		this.myFrame = myFrame;
		start();
	}
	
	public XYZDistanceCalculator(double x1, double y1, double z1, double x2, double y2, double z2) {
		this.x1 = x1;
		this.x2 = x2;
		this.y1 = y1;
		this.y2 = y2;
		this.z1 = z1;
		this.z2 = z2;
	}
	
	public void run() {
		dx = roundToDecimals(x2 - x1, 3);
		dy = roundToDecimals(y2 - y1, 3);
		dz = roundToDecimals(z2 - z1, 3);
		vector = "( " + dx + " ; " + dy + " ; " + dz + " )";
		distance = roundToDecimals(Math.sqrt((Math.pow(dx, 2) + Math.pow(dy, 2) + Math.pow(dz, 2))), 3);
		if(myFrame != null){
			myFrame.setDataPanel(new PointsIn3DOutputGui(x1,y1,x2,y2,z1,z2,distance,vector), "XYZDISTANCE_OUTPUT");
		}
	}
}
